package com.homework;

/**
 * @Author WaveHi
 * @Date 11/8/2021 上午 8:54
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
public class ItemDemo {

    public static void main(String[] args) {

        //获取文本信息
        String text =  "name：移动硬盘;price：58.0";

        /*
        //计算文本信息处理后产生的结果数量
        int count = 0;//统计个数
        int index = 0;
        boolean hasString = false;//标记是否还有指定字符
        while(true) {

            hasString = false;

            if(index > text.length) {

                break;

            }

            if(text.indexOf("; ",index) > 0) {

                count++;
                index = text.indexOf("; ",index);
                hasString = true;

            }

            if(hasString) {

                index++;


            } else {

                break;

            }

        }

        //接收处理文本信息的结果
        String[] words = new String[count];
        */

        //处理文本信息
        String[] words = text.split("\\;");
        String[] names = words[0].split("\\：");
        String[] prices = words[1].trim().split("\\：");

        //创建对象
        Item i1 = new Item(names[1],Double.parseDouble(prices[1].trim()));


    }

}

//Item
class Item {

    private String name;//名称
    private double price;//价格

    public Item() {

    }

    public Item(String name,double price) {

        this.name = name;
        this.price = price;

    }

    public void setName(String name) {

        this.name = name;

    }

    public String getName() {

        return name;

    }

    public void setPrice(double price) {

        this.price = price;

    }

    public double getPrice() {

        return price;

    }

}

